// $Id: response.h 41 2011-04-15 15:44:51Z cedric.shih@gmail.com $
/*
 * Copyright (C) 2010 Cedric Shih <cedric.shih@gmail.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#ifndef RESPONSE_H_
#define RESPONSE_H_

#include "niohttp.h"
#include "common.h"

enum niohttp_response_state {
	NIOHTTP_RESP_LINE,
	NIOHTTP_RESP_HEADER_NAME,
	NIOHTTP_RESP_HEADER_VALUE,
	NIOHTTP_RESP_HEADER_ENTRY,
	NIOHTTP_RESP_HEADER,
	NIOHTTP_RESP_METADATA,
};

struct niohttp_response {
	enum niohttp_response_state state;
	char *protocol;
	struct niohttp_version version;
	int code;
	char *reason;
	struct niohttp_headers *header;
	size_t mark;
	char *token;
	char *value;
};

int niohttp_response_nset_protocol(struct niohttp_response *resp,
		const char *protocol, size_t len);

int niohttp_response_nset_version(struct niohttp_response *resp,
		const char *version, size_t len);

int niohttp_response_nset_reason(struct niohttp_response *resp,
		const char *reason, size_t len);

void niohttp_response_reset(struct niohttp_response *resp);

int niohttp_response_parse(struct niohttp_response *resp,
		struct niobuffer *buffer);

int niohttp_response_parse_line(struct niohttp_response *resp,
		struct niobuffer *buffer);

int niohttp_response_parse_header(struct niohttp_response *resp,
		struct niobuffer *buffer);

#endif /* RESPONSE_H_ */
